#author  conan
#QQ 634598660
####### export_log
$exe_path = Split-Path -Parent $MyInvocation.MyCommand.Definition
$date=(Get-Date).ToString(‘yyyyMMdd’)
Start-Transcript KaTeX parse error: Undefined control sequence: \OpenMaillog at position 13: exe_path\log\̲O̲p̲e̲n̲M̲a̲i̲l̲l̲o̲g̲date.txt -Append -Force
######## param
$ex_account = “conan”
$ex_password = “Y29uYW5sb3Zldml2aWFu”
$ex_url = “http://www.google.com/powershell/”
$username=“conan_ft”
######## password security
$sec_ex_password = ConvertTo-SecureString –String $ex_password –AsPlainText -Force
$ex_cred = new-object –TypeName System.Management.Automation.PSCredential –ArgumentList $ex_account, $sec_ex_password
######## connection
$ex_session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $ex_url -Authentication Kerberos -Credential $ex_cred
######## import
Import-PSSession $ex_session -AllowClobber
######## use exchange
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
######################################################

######## query_mailbox
get-mailbox -ResultSize unlimited | select-string $username

######## create_mailbox
$mail_pass = ConvertTo-SecureString -AsPlainText 123456.abc -Force
new-mailbox -Name $username -UserPrincipalName $username@google.com -Password $mail_pass

######## disable_mailbox
disable-mailbox -Identity $username


$ad_account="conan"
$ad_password="Y29uYW5sb3Zldml2aWFu"
$sec_ad_password = ConvertTo-SecureString –String $ad_password –AsPlainText -Force
get-aduser -filter * | select-string $ad_account
Set-ADAccountPassword -Identity $ad_account -Reset -NewPassword $sec_ad_password